var express = require('express');
var router = express.Router();



/* GET users listing. */
router.get('/', function (req, res, next) {
  var clientIp = getIp(req);
  console.log('客户端ip', clientIp);
  res.send('Hello World' + clientIp);
});

//通过req的hearers来获取客户端ip
var getIp = function (req) {
  var ip = req.headers['x-real-ip'] || req.headers['x-forwarded-for'] || req.connection.remoteAddres || req.socket.remoteAddress || '';
  if (ip.split(',').length > 0) {
    ip = ip.split(',')[0];
  }
  return ip;
}


module.exports = router;
